﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;//引入命名空间
using Tank.Properties;//

namespace Tank
{
    /// <summary>
    /// 玩家类
    /// </summary>
    public abstract class Player : Roles
    {

        #region 观察者集合

        #endregion
        #region 构造函数
        /// <summary>
        /// 构造函数（无参）
        /// </summary>
        public Player()
        {
        }

        /// <summary>
        /// 构造函数（带参）
        /// </summary>
        /// <param name="x">Tank所处的X坐标</param>
        /// <param name="y">Tank所处的Y坐标</param>
        /// <param name="width">Tank的宽度</param>
        /// <param name="height">Tank的高度</param>
        /// <param name="life">Tank的生命</param>
        /// <param name="sp">Tank的速度</param>
        /// <param name="dir">Tank的方向</param>
        /// <param name="dir">Tank的图片</param>
        public Player(int x, int y, int width, int height, int life, int sp, Direction dir, Image[] img)
            : base(x, y, width, height, life, sp, dir)
        {
            this.Img = img;
            this.Enable = true;
        }
        #endregion

        #region MyRegion

        /// <summary>
        /// 调整Tank方向
        /// </summary>
        public override void AdjustDir()
        {
            if (DirU)  this.Dir = Direction.U; 
            else 
            if (DirD) this.Dir = Direction.D;
            else 
            if (DirL) this.Dir = Direction.L;
            else 
            if (DirR) this.Dir = Direction.R;
        }

        /// <summary>
        /// 重写移动方法（Player）
        /// </summary>
        public override void Move()
        {
            if (Enable)
            {
                AdjustDir();
                base.Move();
            }
        }

        /// <summary>
        /// 实现是否被击毁方法（player）
        /// </summary>
        public override void IsDoom()
        {
            if (this.Life < 0)
            {
                Sound.Play(@"Sound\blast.wav");
                GameMana.Instance().AddGameElement(new Blast(this.X, this.Y));
                this.X = -100;
                this.Y = -100;
                this.Enable = false;
            }
        }

        /// <summary>
        /// 画出玩家坦克
        /// </summary>
        /// <param name="g"></param>
        public override void Draw(Graphics g)
        {
            switch (this.Dir)
            {
                case Direction.U:
                    g.DrawImage(Img[0], this.X, this.Y);
                    break;
                case Direction.D:
                    g.DrawImage(Img[1], this.X, this.Y);
                    break;
                case Direction.L:
                    g.DrawImage(Img[2], this.X, this.Y);
                    break;
                case Direction.R:
                    g.DrawImage(Img[3], this.X, this.Y);
                    break;
            }
            base.ShowHP(g);
            IsDoom();
        }

        /// <summary>
        /// 按下移动键
        /// </summary>
        /// <param name="e"></param>
        public abstract void KeyDonw(KeyEventArgs e);

        /// <summary>
        /// 释放移动键
        /// </summary>
        /// <param name="e"></param>
        public abstract void KeyUp(KeyEventArgs e);

        /// <summary>
        /// 玩家射击
        /// </summary>
        public override void Fire()
        {
            GameMana.Instance().AddGameElement(new PlayerShell(this, 1, 20, 1));
        }

        public void ActionBlock(GameElement element)
        {
           
        }

        #endregion

        #region 坦克图片、移动状态

        /// <summary>
        /// 坦克图片
        /// </summary>
        public Image[] Img { get; set; }

        /// <summary>
        /// 助攻编号
        /// </summary>
        public int AssistNo { get; set; }

        /// <summary>
        /// 是否按下（释放）移动按键
        /// </summary>
        protected bool DirU { get; set; }
        protected bool DirD { get; set; }
        protected bool DirL { get; set; }
        protected bool DirR { get; set; }

        #endregion
    }
}
